package com.link2room.ironhide.facade.impl;

import com.link2room.common.dto.param.base.BaseParamDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.service.ICommonService;
import com.link2room.common.util.ClassConverUtil;
import com.link2room.common.util.L2RAssert;
import com.link2room.ironhide.dto.result.base.L2RGroupRoomtypeDto;
import com.link2room.ironhide.entity.L2RGroupRoomtype;
import com.link2room.ironhide.entity.L2RHotelRoomtype;
import com.link2room.ironhide.facade.IGroupRoomtypeFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;

/**
 * Created by sss on 2016/8/29.
 */
@Component("groupRoomtypeFacadeService")
public class GroupRoomtypeFacadeServiceImpl implements IGroupRoomtypeFacadeService {

    @Resource
    private ICommonService commonService;

    /**
     * 集团房型基础信息列表
     * @param baseParamDto
     * @return
     * @throws Exception
     */
    @Override
    public QueryResult<L2RGroupRoomtypeDto> listGroupRoomType(BaseParamDto baseParamDto)throws Exception{
        QueryResult<L2RGroupRoomtype> groupRoomtypeResult = commonService.findAllEQ(L2RGroupRoomtype.class,ClassConverUtil.copyProperties(baseParamDto,L2RGroupRoomtype.class), baseParamDto.getCurrentPage(), baseParamDto.getPageSize());
        return ClassConverUtil.copyQueryResultToDtoQueryResult(groupRoomtypeResult, L2RGroupRoomtypeDto.class, false);
    }

    /**
     * 集团房型待创建列表
     * @param baseParamDto
     * @return
     * @throws Exception
     */
    @Override
    public List<L2RGroupRoomtypeDto> listGroupRoomTypeNotCreated(BaseParamDto baseParamDto)throws Exception{
        L2RAssert.stringBlank(baseParamDto.getLhotelCode(),"酒店代码为空");
        L2RGroupRoomtype queryGroupRmtype=new L2RGroupRoomtype();
        queryGroupRmtype.setLhotelGroupCode(baseParamDto.getLhotelGroupCode());
        QueryResult<L2RGroupRoomtype> groupRoomtypeResult = commonService.findAllEQ(L2RGroupRoomtype.class,queryGroupRmtype);
        L2RHotelRoomtype querymtype=new L2RHotelRoomtype();
        querymtype.setLhotelGroupCode(baseParamDto.getLhotelGroupCode());
        querymtype.setLhotelCode(baseParamDto.getLhotelCode());
        QueryResult<L2RHotelRoomtype> roomtypeQueryResult = commonService.findAllEQ(L2RHotelRoomtype.class,querymtype);
        if(groupRoomtypeResult.getResultlist()!=null){
            Iterator<L2RGroupRoomtype> groupRmtypeIterator = groupRoomtypeResult.getResultlist().iterator();
            while (groupRmtypeIterator.hasNext()){
                L2RGroupRoomtype l2RGroupRoomtype =groupRmtypeIterator.next();
                if(roomtypeQueryResult.getResultlist()!=null){
                    for(L2RHotelRoomtype roomtype:roomtypeQueryResult.getResultlist()){
                        if(l2RGroupRoomtype.getGroupRmtype().equals(roomtype.getGroupRmtype())){
                            groupRmtypeIterator.remove();
                        }
                    }
                }
            }
        }
        return ClassConverUtil.copyPropertiesListToDtoList(groupRoomtypeResult.getResultlist(),L2RGroupRoomtypeDto.class,false);
    }
}
